﻿<%@ Page Title="My debts" Language="C#" MasterPageFile="~/YouOweMe.Master" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="YouOweMe.Default" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
 
 <asp:ObjectDataSource ID="LendMoneyObjectDataSource" runat="server" 
        TypeName="YouOweMe.BLL.DebtManager"
        SelectMethod="GetDebts" 
        InsertMethod="InsertOneDebt"
        UpdateMethod="CloseOneDebt">
        <SelectParameters>
            <asp:SessionParameter Name="userID" SessionField="UserID" Type="Int64"/>
        </SelectParameters>
        <InsertParameters>
            <asp:SessionParameter Name="IndebtedID" SessionField="UserID" Type="Int64"/>
            <asp:Parameter Name="Comment" Type="String" />
            <asp:Parameter Name="Amount" Type="Double" />
            <asp:Parameter Name="Private" Type="Boolean" DefaultValue="true"/>
            <asp:Parameter Name="userID" Type="Int64" /><%-- ControlID="DebtsListView$PeopleDdl" PropertyName="SelectedValue" />--%>
        </InsertParameters>
    </asp:ObjectDataSource>
    <asp:ListView ID="DebtsListView" runat="server" 
    DataSourceID="LendMoneyObjectDataSource"
    InsertItemPosition="LastItem" oniteminserting="DebtsListView_ItemInserting"
    DataKeyNames="Id" ondatabound="DebtsListView_DataBound">
        <LayoutTemplate>
            <table class="detail_list">
                <thead>
                    <tr>
                        <th scope="col">Date</th>
                        <th scope="col">Lender</th>
                        <th scope="col">Amount</th>
                        <th scope="col">Comment</th>
                        <th scope="col"></th>
                    </tr>
                </thead>
                <tfoot>
                    <tr>
                        <th scope="row">
                            Total
                        </th>
                        <td colspan="5">
                            <asp:Literal ID="TotalLitteral" runat="server" />
                        </td>
                    </tr>
                </tfoot>
                <tbody>
                    <tr id="itemPlaceHolder" runat="server" />
             
            
        </LayoutTemplate>
        <InsertItemTemplate>
           </tbody>
            </table>
            
            <div class="form_list">
                <h2>Add a new debt</h2>
                <asp:ValidationSummary ID="DebtValidationSummary" runat="server"
                 ValidationGroup="DebtValidationGroup" CssClass="validation_errors" DisplayMode="BulletList"/>
                <dl class="event">
                    <dt>Lender</dt>
                    <dd>
                        <asp:ObjectDataSource ID="PeoplesObjectDataSource" runat="server" TypeName="YouOweMe.BLL.PeopleManager"
                            SelectMethod="GetAllPeople">
                            <SelectParameters>
                                <asp:SessionParameter Name="userID" Type="Int64" SessionField="UserID" />
                            </SelectParameters>
                        </asp:ObjectDataSource>
                        <asp:DropDownList ID="PeopleDdl" runat="server" DataSourceID="PeoplesObjectDataSource"
                            DataTextField="Initials" DataValueField="ID" />
                    </dd>
                    <dt>Comment</dt>
                    <dd>
                        <asp:TextBox ID="CommentTextBox" runat="server" Text='<%# Bind("Comment")%>'
                            TextMode="MultiLine" Height="100px" Width="95%" />
                    </dd>
                    <dt>Amount</dt>
                    <dd>
                        <asp:TextBox ID="AmountTextBox" runat="server" Text='<%# Bind("Amount")%>' SkinID="Numeric"
                            ValidationGroup="DebtValidationGroup"/>&nbsp;€
                        <asp:RequiredFieldValidator ID="AmountRequiredFieldValidator" runat="server"
                            ControlToValidate="AmountTextBox"
                            ErrorMessage="Amount is required !"
                            ValidationGroup="DebtValidationGroup"
                            Display="Dynamic" />
                        <asp:CompareValidator runat="server" ID="AmountCompareValidator"
                            ControlToValidate="AmountTextBox"
                            ErrorMessage="Amount must be numeric"
                            Operator="DataTypeCheck"
                            Type="Double"
                            Display="Dynamic"
                            ValidationGroup="DebtValidationGroup"/>  
                        <asp:CompareValidator runat="server" ID="PositiveAmountCompareValidator"
                            ControlToValidate="AmountTextBox"
                            ErrorMessage="Amount must be greater than zero"
                            Operator="GreaterThan"
                            Type="Double"
                            ValueToCompare="0"
                            Display="Dynamic"
                            ValidationGroup="DebtValidationGroup"/>
                    </dd>
                    <dt>Private</dt>
                    <dd>
                        <asp:CheckBox ID="PrivateCheckBox" runat="server" Checked='<%# Bind("Private") %>' />
                    </dd>
                    <dt>Action</dt>
                    <dd>
                        <asp:Button ID="insertOneButton" runat="server" CommandName="Insert" Text="Add a debt"
                         ValidationGroup="DebtValidationGroup" />
                    </dd>
                </dl>
                <br />
            </div>
        </InsertItemTemplate>
        <ItemTemplate>
            <tr>
                <td scope="row">
                    <%# Eval("LoadDate","{0:d}") %>
                </td>
                <td>
                    <%# Eval("Person.Initials")%>
                </td>
                <td>
                    <%# Eval("Amount") %>
                </td>
                <td>
                    <%# Eval("Comment")%>
                </td>
                <td>
                    <asp:ImageButton runat="server" ID="CloseImageButton" 
                        CommandName="Update" SkinID="close"
                        OnClientClick="return confirm('Are you sure that debt is cleared ?');" />
                </td>
            </tr>
        </ItemTemplate>
        <EmptyItemTemplate>
            nothing for now ...
        </EmptyItemTemplate>
    </asp:ListView>

</asp:Content>
